package com.orange.studio.dbk.fragments;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.meta.gui.quickaction.QuickAction;
import com.meta.gui.quickaction.QuickAction.OnActionItemClickListener;
import com.orange.studio.dbk.R;
import com.orange.studio.dbk.activities.HomeActivity;
import com.orange.studio.dbk.dao.FavioritesDAO;
import com.orange.studio.dbk.dto.SongDTO;
import com.orange.studio.dbk.listeners.MainHandler;
import com.orange.studio.uicore.customviews.LoadMoreListViewUICore;
import com.orange.studio.uicore.customviews.LoadMoreListViewUICore.OnLoadMoreListener;
import com.orange.studio.uicore.customviews.ProgressWheelUICore;

public class BaseFragment extends Fragment implements OnClickListener, OnActionItemClickListener,OnLoadMoreListener,MainHandler {
	protected View mView;
	protected View mNotFoundData=null;
	protected View mWaitingForLoading=null;
	protected View mBtnRetry=null;
	protected ProgressWheelUICore mProgress=null;
	protected LoadMoreListViewUICore mListView;
	
	protected int pageNo=1;
	protected HomeActivity mActivity=null;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {		
		return super.onCreateView(inflater, container, savedInstanceState);
	}
	protected void initNotFoundAndLoadingView(){
		mNotFoundData=(LinearLayout)mView.findViewById(R.id.notFoundDataContainer);		
		mWaitingForLoading=(LinearLayout)mView.findViewById(R.id.waitingLoading);
		mProgress=(ProgressWheelUICore)mView.findViewById(R.id.progressWheel);
		mProgress.spin();
		showNotFoundOrLoadingView(false, true);
		mBtnRetry=(ImageView)mView.findViewById(R.id.btnRetry);		
	}
	protected void initRetryButtonListener(){
		mBtnRetry.setOnClickListener(this);
	}
	protected void showNotFoundOrLoadingView(boolean isShowNotFound,boolean isShowLoading){
		if(isShowNotFound){
			mNotFoundData.setVisibility(View.VISIBLE);
		}else{
			mNotFoundData.setVisibility(View.GONE);
		}
		if(isShowLoading){
			mWaitingForLoading.setVisibility(View.VISIBLE);
		}else{
			mWaitingForLoading.setVisibility(View.GONE);
		}
	}
	@Override
	public void onClick(View v) {		
	}
	@Override
	public void onItemClick(QuickAction source, int pos, int actionId) {
		
	}
	@Override
	public void onLoadMore() {
		
	}
	@Override
	public void setLiked(SongDTO song) {
		
	}
	protected void getListFaviorites() {
		if(mActivity==null){
			mActivity=(HomeActivity) getActivity();
		}
		if(mActivity.getFavioriteIds().size()<1){
			List<Integer> listIds=FavioritesDAO.getInstance().getListFaviorites();
			if(listIds!=null && listIds.size()>0){
				mActivity.setFavioriteIds(listIds);
			}
		}
	}
	@Override
	public void onResume() {
		super.onResume();
		mActivity=(HomeActivity) getActivity();
	}
}
